// 编辑话术的 模态框
import React, {useRef} from 'react';
import {Form, message, Modal} from 'antd';
import ProForm, { ProFormText, ProFormSelect, ProFormTextArea, ProFormDigit } from '@ant-design/pro-form';
import {PutEdit} from "@/services/ant-design-pro/order";


const EditorialScript = (props) => {
  const { isShowModal,changeMadal,record,editScript,menuAll } = props
  const [form] = Form.useForm()

  return (
    <div>
        <Modal
          // layout='horizontal'
          // labelCol={{span:4}}
          // wrapperCol={{span:14}}
          // title="编辑话术"
          // trigger={
          //   <a >编辑</a>
          // }
          // onFinish={async (values) => {
          //   console.log(values);
          //   message.success('提交成功');
          //   // 刷新
          //   // ref.current.reset();
          //   return true;
          // }}
          visible={isShowModal}
          title='编辑话术'
          onCancel={changeMadal}
          onOk={()=>{
            form.validateFields().then( async value => {
              // console.log({...value,pid:record.id,service_id:record.id,id:record.id});
              await editScript({...value,pid:record.id,service_id:record.id,id:record.id})
              message.success('修改成功')
            })
            changeMadal()
          }}
        >
          <ProForm
            form={form}
            initialValues={record}
            layout={'horizontal'}
            labelCol={{span:4}}
            wrapperCol={{span:14}}
            submitter={false}
          >
            <ProFormSelect
              name="category_id"
              label="话术分类"
              request={async ()=>{
                const arr1 = menuAll.map((item)=>{
                    return {label:item.nickname,value:item.id}
                })
                return [{label:'全部',value:'all'},...arr1]
              }}
              placeholder="请选择话术分类"
              rules={[{ required: true, message: '请选择话术分类' }]}
            />
            <ProFormText
              width="md"
              name="title"
              label="话术标题"
              placeholder="请输入话术标题"
            />
            <ProFormTextArea
              name="content"
              label="话术内容"
              placeholder="请输入话术内容"
            />
            <ProFormDigit
              width={100}
              name="sort"
              label="排序"
            />
          </ProForm>
        </Modal>
    </div>
  );
};

export default EditorialScript;
